package com.StarStudio.DAO;

import com.ruoyi.common.core.Entity.PanicBuyingCoupons;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PanicBuyingCouponsDAO {

    List<PanicBuyingCoupons> findPanicBuyingCouponsList(PanicBuyingCoupons panicBuyingCoupons);

    @Select("select count(panic_buying_coupons_id) from panic_buying_coupons where del_flag = false")
    long findTotalRecord();

    @Select("select * from panic_buying_coupons where coupons_id = #{coupons_id}")
    PanicBuyingCoupons findByCoupons_id(long coupons_id);

    @Update("update panic_buying_coupons set coupons_id = #{coupons_id},panic_buying_price = #{panic_buying_price}," +
            "panic_buying_coupons_stock = #{panic_buying_coupons_stock},panic_buying_start_time = #{panic_buying_start_time}," +
            "panic_buying_end_time = #{panic_buying_end_time},panic_buying_status = #{panic_buying_status},del_flag = #{del_flag} where panic_buying_coupons_id = #{panic_buying_coupons_id}")
    int updatePanicBuyingCoupons(PanicBuyingCoupons panicBuyingCoupons);

    @Select("select * from panic_buying_coupons")
    List<PanicBuyingCoupons> PanicBuyingCouponsList();

    @Insert("insert into panic_buying_coupons values(null,#{coupons_id},#{panic_buying_price},#{panic_buying_coupons_stock},#{panic_buying_start_time}," +
            "#{panic_buying_end_time},#{panic_buying_status},#{del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "panic_buying_coupons_id",keyColumn = "panic_buying_coupons_id")
    void AddPanicBuyingCoupons(PanicBuyingCoupons panicBuyingCoupons);

//    @Delete("delete from panic_buying_coupons where panic_buying_coupons_id = #{panic_buying_coupons_id}")
    @Update("update panic_buying_coupons set del_flag = true, panic_buying_coupons_stock = 0 where panic_buying_coupons_id = #{panic_buying_coupons_id}")
    int DeletePanicBuyingCoupons(long panic_buying_coupons_id);

    @Select("select * from panic_buying_coupons where panic_buying_status = #{status}")
    List<PanicBuyingCoupons> findByStatus(int status);

    @Select("select panic_buying_coupons_stock from panic_buying_coupons where panic_buying_coupons_id = #{Panic_buying_coupons_id}")
    int findPanic_buying_coupons_stockByPanic_buying_coupons_id(long Panic_buying_coupons_id);

    @Select("select coupons_id from panic_buying_coupons where panic_buying_coupons_id = #{panic_buying_coupons_id}")
    long findCouponsIdByPBCId(long panic_buying_coupons_id);

    @Select("select IFNULL(panic_buying_coupons_stock,0) from panic_buying_coupons where coupons_id = #{coupon_id} and del_flag = false")
    Integer findPBCouponsStockByCouponsId(long coupon_id);
}
